<?php

/*
*
* BEGIN game_management_ui.php
*
*
* Dazzler Game Management Uis
* @Description: The class creates all the UIs for the game management
* @Authors: Salman, Wits University
* @Copyright: © Wits University 2011 - All Rights Reserved
* @License: BSD License (http://www.linfo.org/bsdlicense.html)
*
*
* BEGIN CHANGELOG
* Developers working on thee files are REQUIRED to maintain this CHANGELOG.
* Please ensure you follow the Changelog Guidelines: http://code.google.com/p/dazzler/wiki/DazzlerDevelopGuideline?ts=1315476570&updated=DazzlerDevelopGuideline
* !==================================================================================================================================================================
*
* VERSION 1.0.0
*	+ File Created, Salman, 26 September 2011
*
* ==================================================================================================================================================================!
* END CHANGELOG
*/


/*******************************************************************************************************************************************************************
*
* BEGIN Direct Call Check
*
/******************************************************************************************************************************************************************/
global $doNotCallThisScriptDirectly;
if ($doNotCallThisScriptDirectly != 1)
{
	/* Read the ini language file */
	$ini_lang_array = array();
	$clientlang = explode(",", strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']));
	$lang_ini_array = (file_exists("lang/" . trim($clientlang[0]) . ".ini")) ? parse_ini_file("lang/" . trim($clientlang[0]) . ".ini", true) : parse_ini_file("lang/en.ini", true);
	die ($lang_ini_array['ERRORS']['doNotCallThisScriptDirectly']);
}
/*******************************************************************************************************************************************************************
*
* END Direct Call Check
*
/******************************************************************************************************************************************************************/

class game_management_ui extends baseClass
{

    private $htmlelementsbuilder;

    private $parsesiteconfig;

    public function  __construct()
    {
    $this->htmlelementsbuilder = new htmlelementsbuilder();
    $this->parsesiteconfig = new parsesiteconfig();
    parent::parseLanguageErrorLogFile();
    }

    private function buildAddGameForm()
    {
        $AddGameWindow = '	<style>
	#feedback { font-size: 1.4em; }
	.selectable-teams .ui-selecting { background: #FECA40; }
	.selectable-teams .ui-selected { background: #F39814; color: white; }
	.selectable-teams { list-style-type: none; margin: 0; padding: 0; }
	.selectable-teams li { margin: 3px; padding: 1px; float: left; width: 100px; height: 18px; font-size: 1em; text-align: center; }
        .teamsSelectContainers {float:left; width:220px; border:1px solid #CCCCCC;padding:5px 5px 5px 5px; margin:5px 5px 5px 5px;}
	</style>';
        $AddGameWindow .="<div style =' border: 1px solid transparent; padding: 7px' class='errorMessageDiv'> </div>";
        $AddGameWindow .="<div class='responseDiv'> </div>";
        $AddGameWindow .= "<div id='gameMetaDataFromContainer'>";
        $postPath = $this->parsesiteconfig->getURLPath();
        $AddGameWindow .= "<form id='addGameForm' method='post' name='add game form'";
        $AddGameWindow .= $this->htmlelementsbuilder->buildTextInput('matchName', null, 'matchName', TRUE, "Title of Match", 'top') . "<br>";
        $this->htmlelementsbuilder->addOption('ODI50','One Day International (ODI) 50 Overs');
        $this->htmlelementsbuilder->addOption('ODI20','One Day International (ODI) 20 Overs');
        $this->htmlelementsbuilder->setSelected('ODI50');
        $AddGameWindow .= $this->htmlelementsbuilder->buildDropDown("matchType", "Type of Cricket Match", "top");
        $AddGameWindow .= $this->htmlelementsbuilder->buildTextInput('matchVenue', "ertert", 'matchVenue', TRUE, "Match Venue", 'top') . "<br>";
        $AddGameWindow .= $this->htmlelementsbuilder->buildTextInput('firstEmpire', "Aleem Dar", 'firstEmpire', TRUE, "First Umpire", 'top') . "<br>";
        $AddGameWindow .= $this->htmlelementsbuilder->buildTextInput('secondEmpire', "Rudi Koertzen", 'secondEmpire', TRUE, "Second Umpire", 'top') . "<br>";
        $AddGameWindow .= $this->htmlelementsbuilder->buildTextInput('thirdEmpire', "Billy Doctrove", 'thirdEmpire', TRUE, "Third or TV Umpire", 'top') . "<br>";
        $AddGameWindow .= $this->htmlelementsbuilder->buildTextInput('reserveEmpire', "Simon Taufel", 'reserveEmpire', TRUE, "Reserve Umpire", 'top') . "<br>";
        $AddGameWindow .= $this->htmlelementsbuilder->buildTextInput('matchReferee', "Daryl Harper", 'matchReferee', TRUE, "Match Referee", 'top') . "<br>";
        $GameAdmin = new GameAdmin();
        $TeamArray = $GameAdmin->getAllTeamsByName();
        $teamAListItem = array();
        $teamBListItem = array();
        foreach ($TeamArray as $team) {
            $listItem = new htmlcodemaker('li');
            $listItem->set(array('class'=>'ui-state-default','name'=>$team['TEAM_POOL_ID'], 'text'=>$team["TEAM_POOL_NAME"]));
                  $teamAListItem[] = $listItem;
                  $teamBListItem[] = $listItem;
        }
        $teamANumberedList = new htmlcodemaker('ol');
        $teamANumberedList->set(array('id'=>'selectable-teamHome','class'=>'selectable-teams'));
        $teamANumberedList->inject($teamAListItem);
        $AddGameWindow .= "<div id='teamsHomeSelectContainers' class='teamsSelectContainers ui-corner-all'><h3>Select Home Team</h3>".$teamANumberedList->output()."</div>";

        $teamBNumberedList = new htmlcodemaker('ol');
        $teamBNumberedList->set(array('id'=>'selectable-teamAway','class'=>'selectable-teams'));
        $teamBNumberedList->inject($teamAListItem);
        $AddGameWindow .= "<div id='teamsAwaySelectContainers' class='teamsSelectContainers ui-corner-all'><h3>Select Away Team</h3>".$teamBNumberedList->output()."</div>";


        
        $AddGameWindow .="</form>";
        $AddGameWindow .= "</div>";
        $AddGameWindow .= "<div id='matchTossDataContainer'></div>";
        return $AddGameWindow;
    }


    private function buildGameTossForm($homeTeamID,$homeTeamName,$awayTeamID,$awayTeamName)
    {
        $GameAdmin = new GameAdmin();
        $homeTeamShortName = $GameAdmin->getTeamFromPool($homeTeamID);
        $homeTeamShortName = strtolower($homeTeamShortName);
        $awayTeamShortName = $GameAdmin->getTeamFromPool($awayTeamID);
        $awayTeamShortName = strtolower($awayTeamShortName);
        $gameTossForm = "<div style='width:400px; height:125px;'>";
        $gameTossForm .= "<div class ='teamLogo ".$homeTeamShortName."_home_logo'></div><p style='float:left; padding:30px 0px 0px 0px;'><strong> $homeTeamName Vs.";
        $gameTossForm .= " $awayTeamName </strong></p><div class ='teamLogo ".$awayTeamShortName."_home_logo'></div>";
        $gameTossForm .= "</div>";
        //print_r($homeTeamDetailsArray);
        $this->htmlelementsbuilder->addOption($homeTeamID,$homeTeamName);
        $this->htmlelementsbuilder->addOption($awayTeamID,$awayTeamName);
        $this->htmlelementsbuilder->setSelected($homeTeamID);
        $gameTossForm .= $this->htmlelementsbuilder->buildRadioButton('batFirstTeam', "Select team to bat in the first innings of the game:")."<br><br>";
        $gameTossForm .= $this->htmlelementsbuilder->buildTextArea("tossCommentary", null, "tossCommentary", true, "Enter commentary on the match toss", 'top',5,34);
        return $gameTossForm;

    }




    private function buildInsertPlayerIntoForm($gameID)
    {
        $GameAdmin = new GameAdmin();
        $PlayerAdmin = new PlayerAdmin();
        $homeTeamDetailsArray = $GameAdmin->getHomeTeam($gameID);
        $awayTeamDetailsArray = $GameAdmin->getAwayTeam($gameID);
        $homeTeamShortName = $homeTeamDetailsArray['TEAM_POOL_SNAME'];
        $awayTeamShortName = $awayTeamDetailsArray['TEAM_POOL_SNAME'];
        $homeTeamShortName = strtolower($homeTeamShortName);
        $awayTeamShortName = strtolower($awayTeamShortName);

        $teamPoolID = $GameAdmin->getTeamPoolId($homeTeamDetailsArray['TEAM_POOL_NAME']);
        $home = $GameAdmin->getTeamFromPool($teamPoolID);
        //echo $homeTeamDetailsArray['TEAM_POOL_NAME'];
        $homeTeamPlayerPoolArray = $PlayerAdmin->getPlayersByPoolName($homeTeamDetailsArray['TEAM_POOL_NAME']);
        $awayTeamPlayerPoolArray = $PlayerAdmin->getPlayersByPoolName($awayTeamDetailsArray['TEAM_POOL_NAME']);
   // print_r($awayTeamPlayerPoolArray);
        $homePlayerListItemArray = array();
       // print_r($homeTeamDetailsArray);
                $parseSiteConfig = new parsesiteconfig();
$rootpath = $parseSiteConfig->getRootPath();
        $loadType = $parseSiteConfig->getLoadType();

        $ball_icon_path = "$rootpath/themes/$loadType/custom/images/commentator/ball_icon_transparent.png";
        $bat_icon_path = "$rootpath/themes/$loadType/custom/images/commentator/bat_icon_transparent.png";
        $wicketkeeper_icon_path = "$rootpath/themes/$loadType/custom/images/commentator/wicket_keeper_icon_transparent.png";
        $captain_icon_path = "$rootpath/themes/$loadType/custom/images/commentator/cricket_captain_icon_transparent.png";
        $help_icon_path = "$rootpath/themes/$loadType/custom/images/commentator/help-icon.png";
        $homeTeamIcon = "$rootpath/themes/$loadType/custom/images/logos/".$homeTeamShortName."_logo.png";
        $awayTeamIcon = "$rootpath/themes/$loadType/custom/images/logos/".$awayTeamShortName."_logo.png";
        //$isBatsmanIcon = new htmlcodemaker('span');
        //$isBatsmanIcon->set(array('class'=>'isBatsman','text'=>"<img class='batIcon' src=$bat_icon_path alt='batsman' width='23' height='23' />"));

//        $isWicketKeeperIcon = new htmlcodemaker('span');
//        $isWicketKeeperIcon->set(array('class'=>'isWicketKeeper','text'=>"<img src=$wicketkeeper_icon_path alt='wicketkeeper' width='23' height='23' />"));

        $homeTeamLogo = new htmlcodemaker('span');
        $homeTeamLogo->set(array('class'=>'logo','style'=>'float:left; margin:0px 7px 0px 7px;','text'=>"<img name=$homeTeamShortName src=$homeTeamIcon alt=$homeTeamShortName height='30' />"));

        $awayTeamLogo = new htmlcodemaker('span');
        $awayTeamLogo->set(array('class'=>'logo','style'=>'float:left; margin:0px 7px 0px 7px;','text'=>"<img name=$awayTeamShortName src=$awayTeamIcon alt='$awayTeamShortName' height='30' />"));

        foreach ($homeTeamPlayerPoolArray as $homePlayer) {

           $playerAttribiutesArray= array();

           $homePlayerListItemText= new htmlcodemaker('span');
           $homePlayerListItemText->set(array('class'=>'playerTextContainer','text' => $homePlayer['PLAYER_POOL_FNAME']." ".$homePlayer['PLAYER_POOL_LNAME']));
           $playerAttribiutesArray[] = $homePlayerListItemText;


          if ($PlayerAdmin->isPlayerSpecialistBatsman($homePlayer['PLAYER_POOL_ID']))
           {
            $isBatsmanIcon1 = new htmlcodemaker('span');
            $isBatsmanIcon1->set(array('class'=>'isBatsman','text'=>"<img class='batIcon' name=".$homePlayer['PLAYER_POOL_ID']." src=$bat_icon_path alt='batsman' width='17' height='17' />"));
            $playerAttribiutesArray[] = $isBatsmanIcon1;
           }

           if($PlayerAdmin->isPlayerWicketkeeper($homePlayer['PLAYER_POOL_ID']))
           {
            $isWicketKeeperIcon = new htmlcodemaker('span');
            $isWicketKeeperIcon->set(array('class'=>'isWicketKeeper','text'=>"<img class='wicketkeeperIcon' name=".$homePlayer['PLAYER_POOL_ID']." src=$wicketkeeper_icon_path alt='wicketkeeper' width='17' height='17' />"));
            $playerAttribiutesArray[] = $isWicketKeeperIcon;
           }

           if ($PlayerAdmin->isPlayerBowler($homePlayer['PLAYER_POOL_ID']))
           {
            $isBowlerIcon = new htmlcodemaker('span');
            $isBowlerIcon->set(array('class'=>'isBowler','text'=>"<img class='bowlerIcon' name=".$homePlayer['PLAYER_POOL_ID']." src=$ball_icon_path alt='bowler' width='17' height='17' />"));
            $playerAttribiutesArray[] = $isBowlerIcon;
           }

           $isCaptainIcon = new htmlcodemaker('span');
           $isCaptainIcon->set(array('class'=>'isCaptain','text'=>"<img name=".$homePlayer['PLAYER_POOL_ID']." src=$captain_icon_path alt='captain' width='17' height='17' />"));
           $playerAttribiutesArray[] = $isCaptainIcon;

            $homePlayerListItem = new htmlcodemaker('div');
            $homePlayerListItem->set(array('id'=>'sortable-homeTeam','class'=>'ui-state-default','name'=>$homePlayer['PLAYER_POOL_ID']));
            $homePlayerListItem->inject($playerAttribiutesArray);
            $homePlayerListItemArray[]=$homePlayerListItem;
        }

        $awayPlayerListItemArray = array();
        foreach ($awayTeamPlayerPoolArray as $homePlayer) {
              $playerAttribiutesArray= array();

           $homePlayerListItemText= new htmlcodemaker('span');
           $homePlayerListItemText->set(array('class'=>'playerTextContainer','text' => $homePlayer['PLAYER_POOL_FNAME']." ".$homePlayer['PLAYER_POOL_LNAME']));
           $playerAttribiutesArray[] = $homePlayerListItemText;

           if ($PlayerAdmin->isPlayerSpecialistBatsman($homePlayer['PLAYER_POOL_ID']))
           {
            $isBatsmanIcon1 = new htmlcodemaker('span');
            $isBatsmanIcon1->set(array('class'=>'isBatsman','text'=>"<img class='batIcon' name=".$homePlayer['PLAYER_POOL_ID']." src=$bat_icon_path alt='batsman' width='17' height='17' />"));
            $playerAttribiutesArray[] = $isBatsmanIcon1;
           }

           if($PlayerAdmin->isPlayerWicketkeeper($homePlayer['PLAYER_POOL_ID']))
           {
            $isWicketKeeperIcon = new htmlcodemaker('span');
            $isWicketKeeperIcon->set(array('class'=>'isWicketKeeper','text'=>"<img class='wicketkeeperIcon' name=".$homePlayer['PLAYER_POOL_ID']." src=$wicketkeeper_icon_path alt='wicketkeeper' width='17' height='17' />"));
            $playerAttribiutesArray[] = $isWicketKeeperIcon;
           }

           if ($PlayerAdmin->isPlayerBowler($homePlayer['PLAYER_POOL_ID']))
           {
            $isBowlerIcon = new htmlcodemaker('span');
            $isBowlerIcon->set(array('class'=>'isBowler','text'=>"<img class='bowlerIcon' name=".$homePlayer['PLAYER_POOL_ID']." src=$ball_icon_path alt='bowler' width='17' height='17' />"));
            $playerAttribiutesArray[] = $isBowlerIcon;
           }

           $isCaptainIcon = new htmlcodemaker('span');
           $isCaptainIcon->set(array('class'=>'isCaptain','text'=>"<img name=".$homePlayer['PLAYER_POOL_ID']." src=$captain_icon_path alt='captain' width='17' height='17' />"));
           $playerAttribiutesArray[] = $isCaptainIcon;

            $awayPlayerListItem = new htmlcodemaker('div');
            $awayPlayerListItem->set(array('id'=>'sortable-awayTeam','class'=>'ui-state-default','name'=>$homePlayer['PLAYER_POOL_ID']));
            $awayPlayerListItem->inject($playerAttribiutesArray);
            $awayPlayerListItemArray[]=$awayPlayerListItem;

        }

        $homePlayerAvailableList = new htmlcodemaker('div');
        $homePlayerAvailableList->set(array('id'=>'sortable-homeTeamProspectivePlayers','class'=>'connectedSortable-homeTeam'));
        $homePlayerAvailableList->inject($homePlayerListItemArray);

        $awayPlayerAvailableList = new htmlcodemaker('div');
        $awayPlayerAvailableList->set(array('id'=>'sortable-awayTeamProspectivePlayers','class'=>'connectedSortable-awayTeam'));
        $awayPlayerAvailableList->inject($awayPlayerListItemArray);

            $EmptyhomePlayerListItem = new htmlcodemaker('div');
            $EmptyhomePlayerListItem->set(array('id'=>'emptySortable-homeTeam','class'=>'ui-state-highlight ui-state-disabled','text'=>'Insert Players into Match'));
            //$homePlayerListItemArray[]=$homePlayerListItem;

            $EmptyawayPlayerListItem = new htmlcodemaker('div');
            $EmptyawayPlayerListItem->set(array('id'=>'emptySortable-awayTeam','class'=>'ui-state-highlight ui-state-disabled','text'=>'Insert Players into Match'));

        $homePlayerGameList = new htmlcodemaker('div');
        $homePlayerGameList->set(array('id'=>'sortable-homeTeamPlayers','class'=>'connectedSortable-homeTeam'));
        $homePlayerGameList->inject($EmptyhomePlayerListItem);

        $awayPlayerGameList = new htmlcodemaker('div');
        $awayPlayerGameList->set(array('id'=>'sortable-awayTeamPlayers','class'=>'connectedSortable-awayTeam'));
        $awayPlayerGameList->inject($EmptyawayPlayerListItem);


        $playerInsertContent = '
            	<style>
	#sortable-awayTeamPlayers, #sortable-homeTeamPlayers, #sortable-awayTeamProspectivePlayers, #sortable-homeTeamProspectivePlayers { list-style-type: none; margin: 0; padding: 0; float: left; margin: 5px; }
	#sortable-homeTeamAvailableContainer, #sortable-awayTeamAvailableContainer {margin:4px; padding:6px; float:left; width:280px; clear:left; height:300px; overflow:scroll; }
        #sortable-homeTeamActualContainer, #sortable-awayTeamActualContainer {margin:4px; padding:6px; float:left; width:280px; clear:right; }
        .ui-state-highlight { height: 1.8em; line-height: 0.8em; }
        #sortable-awayTeamPlayers div, #sortable-homeTeamPlayers div, #sortable-awayTeamProspectivePlayers div,#sortable-homeTeamProspectivePlayers div { margin: 0px 3px 3px 3px; height: 1em; padding: 10px 10px 17px 10px; font-size: 0.8em; width:90%;}
        #homeTeamContainer, #awayTeamContainer {margin:4px; padding:6px; float:left;}
        </style>
        ';

        $playerInsertContent .= "<style> .isBowler {
	margin: 0px 1px 0px 1px;
	float: right;
            }
        .isBatsman, .isWicketKeeper, .isCaptain {
	margin: 0px 1px 0px 1px;
	float: right;
            }

            .playerTextContainer{
            margin: 1px 15px 1px 4px;
            float: left;
            width: 100px;
            }
</style>";
        $playerInsertContent .= "  <div style =' border: 1px solid transparent; padding: 7px' class='responseDiv'> </div>
        <div style =' border: 1px solid transparent; padding: 7px' class='errorMessageDiv'> </div>
<p><span class='ui-icon ui-icon-info' style='float:left; margin:0 7px 20px 0;'></span>Drag and drop players between the two lists and order them according to the batting line up in the players for match container. <span style='padding:0px 0px 0px 0px; margin:0px 50px 0px 50px; float:right;' id='helpIcon'><span style='margin:0px 0px 0px 0px;'><b>More Info</b></span><img src=$help_icon_path height='25' width='25' alt='help' /></span></p>
<div id='helpInfo'>
<p><span class='ui-icon ui-icon-info' style='float:left; margin:0 7px 20px 0;'></span>The <img src=$bat_icon_path alt='batsman' width='23' height='23' /> icon indicates that the player is a specialist batsman.</p>
<p><span class='ui-icon ui-icon-info' style='float:left; margin:0 7px 20px 0;'></span>The <img src=$wicketkeeper_icon_path width='23' height='23' /> icon indicates that the player is tasked to be one of the wicketkeepers for the team. Only one wicketkeeper from a team can be selected to play in a match.</p>
<p><span class='ui-icon ui-icon-info' style='float:left; margin:0 7px 20px 0;'></span>The <img src=$ball_icon_path alt='bowler' width='23' height='23' /> icon indicates that the player is a specialist bowler. Select this icon if the player is going to be bowling in this match. Atleast three players need to be selected to be bowlers for the team.</p>
<p><span class='ui-icon ui-icon-info' style='float:left; margin:0 7px 20px 0;'></span>The <img src=$captain_icon_path alt='captain' width='23' height='23' /> icon indicates that the player is a cpatain of the team. Select this icon if the player is going to be the captain of the team for this match. Only one player can be selected to be captain.</p>
        </div><br>";
        $playerInsertContent .= "<div id='homeTeamContainer' class='ui-widget-content ui-corner-all'>".$homeTeamLogo->output()."<h2>Home Team - ".$homeTeamDetailsArray['TEAM_POOL_NAME']."</h2>";
        $playerInsertContent .= "<div id='sortable-homeTeamAvailableContainer' class='ui-widget-content'><h2>Available Players</h2>".$homePlayerAvailableList->output()."</div>";
        $playerInsertContent .= "<div id='sortable-homeTeamActualContainer' class='ui-widget-content'><h2> Players for this Match</h2>".$homePlayerGameList->output()."</div>";
        $playerInsertContent .= "</div>";
         $playerInsertContent .= "<div id='awayTeamContainer' class='ui-widget-content ui-corner-all'>".$awayTeamLogo->output()."<h2>Away Team - ".$awayTeamDetailsArray['TEAM_POOL_NAME']."</h2>";
        $playerInsertContent .= "<div id='sortable-awayTeamAvailableContainer' class='ui-widget-content ui'><h2>Available Players</h2>".$awayPlayerAvailableList->output()."</div>";
        $playerInsertContent .= "<div id='sortable-awayTeamActualContainer' class='ui-widget-content'><h2> Players for this Match</h2>".$awayPlayerGameList->output()."</div>";
        $playerInsertContent .= "</div>";
        return $playerInsertContent;
       //  print_r($awayTeamPlayerPoolArray);
    }


    private function buildListAllGames()
    {
        $matchListContent = null;
        $matchListContent .="<br /><br /><h2>Live! Games</h2>";
   
        $GameAdmin = new GameAdmin();
        $GamesArray = $GameAdmin->getAllGames();
        $UserLogic = new UserLogic();
        $numberofPairEntries = count($GamesArray);
       // print_r($GamesArray);
     $matchListContent .= '<style>
	#tabs{margin-bottom:5px; }
	.tabs-bottom { position: relative; }
	.tabs-bottom .ui-tabs-panel { height: 500px; overflow: auto;  }
	.tabs-bottom .ui-tabs-nav { position: absolute !important; left: 0; bottom: 0; right:0; padding: 0 0.2em 0.2em 0;  }
	.tabs-bottom .ui-tabs-nav li { margin-top: -2px !important; margin-bottom: 2px !important; border-top: none; border-bottom-width: 1px; }
        .matchTabs {width:140px; overflow: hidden;}
.ui-tabs-selected { margin-top: -3px !important; }

	</style>
        <div id="tabs" class="tabs-bottom"><ul>';
        for ($i=0;$i<($numberofPairEntries/2);$i++)
        {
            $x2 = 2*$i;
            //print_r($GamesArray[$x2]);
           $MatchTitle = $GamesArray[$x2]['GAME_TIT'];
           $GameType = $GamesArray[$x2]['GAME_TYPE'];
           $GameVenue = $GamesArray[$x2]['GAME_VEN'];
           $GameToss = $GamesArray[$x2]['GAME_TOSS'];
           $GameUmpire1 = $GamesArray[$x2]['GAME_UMP1'];
           $GameUmpire2 = $GamesArray[$x2]['GAME_UMP2'];
           $TVUmpire = $GamesArray[$x2]['GAME_UMP_TV'];
           $isGameActiveBool = $GamesArray[$x2]['GAME_ACTIVE'];
           $gameFinalResult = $GamesArray[$x2]['GAME_FINALRESLT'];
           $arePlayerFinalizedBool = $GamesArray[$x2]['GAME_PLAYERSFINALSD'];
           $gameID = $GamesArray[$x2]['GAME_GAME_ID'];
           $homeTeamName = $GamesArray[$x2]['TEAM_POOL_NAME'];
           $awayTeamName = $GamesArray[($x2+1)]['TEAM_POOL_NAME'];
            $homeTeamShortName = $GamesArray[$x2]['TEAM_POOL_SNAME'];
            $awayTeamShortName = $GamesArray[($x2+1)]['TEAM_POOL_SNAME'];
            $homeTeamShortName = strtolower($homeTeamShortName);
             $awayTeamShortName = strtolower($awayTeamShortName);

             
         $parseSiteConfig = new parsesiteconfig();
        $rootpath = $parseSiteConfig->getRootPath();
        $loadType = $parseSiteConfig->getLoadType();

        $homeTeamIcon = "$rootpath/themes/$loadType/custom/images/logos/".$homeTeamShortName."_logo.png";
        $awayTeamIcon = "$rootpath/themes/$loadType/custom/images/logos/".$awayTeamShortName."_logo.png";

        $homeTeamLogo = new htmlcodemaker('span');
        $homeTeamLogo->set(array('class'=>'logo','style'=>'float:left; margin:1px 1px 1px 1px;','text'=>"<img name=$homeTeamIcon src=$homeTeamIcon alt=$homeTeamIcon height='45' />"));

        $awayTeamLogo = new htmlcodemaker('span');
        $awayTeamLogo->set(array('class'=>'logo','style'=>'float:left; margin:1px 1px 1px 1px;','text'=>"<img name=$awayTeamIcon src=$awayTeamIcon alt='$awayTeamIcon' height='45' />"));

            if ($isGameActiveBool)
            {

                $trimmedMatchTitle = preg_replace('/\s+/', '', $MatchTitle);
                $matchListContent .= "<li ><a href='#$trimmedMatchTitle' class='matchTabs'>".$homeTeamLogo->output()."<p style='float:left; padding:8px 3px 3px 3px;'> Vs. </p>".$awayTeamLogo->output()."<p align='center' style='clear:both;'><b>$MatchTitle</b><br/><sup>$GameVenue</sup></p></a></li>";

            }



         
        }
         $matchListContent .= " </ul>";


                 for ($i=0;$i<($numberofPairEntries/2);$i++)
        {
            $x2 = 2*$i;
            //print_r($GamesArray[$x2]);
           $MatchTitle = $GamesArray[$x2]['GAME_TIT'];
           $GameType = $GamesArray[$x2]['GAME_TYPE'];
           $GameVenue = $GamesArray[$x2]['GAME_VEN'];
           $GameToss = $GamesArray[$x2]['GAME_TOSS'];
           $GameUmpire1 = $GamesArray[$x2]['GAME_UMP1'];
           $GameUmpire2 = $GamesArray[$x2]['GAME_UMP2'];
           $TVUmpire = $GamesArray[$x2]['GAME_UMP_TV'];
           $isGameActiveBool = $GamesArray[$x2]['GAME_ACTIVE'];
           $gameFinalResult = $GamesArray[$x2]['GAME_FINALRESLT'];
           $arePlayerFinalizedBool = $GamesArray[$x2]['GAME_PLAYERSFINALSD'];
           $gameID = $GamesArray[$x2]['GAME_GAME_ID'];
           $homeTeamName = $GamesArray[$x2]['TEAM_POOL_NAME'];
           $awayTeamName = $GamesArray[($x2+1)]['TEAM_POOL_NAME'];
            $homeTeamShortName = $GamesArray[$x2]['TEAM_POOL_SNAME'];
            $awayTeamShortName = $GamesArray[($x2+1)]['TEAM_POOL_SNAME'];
            $homeTeamShortName = strtolower($homeTeamShortName);
             $awayTeamShortName = strtolower($awayTeamShortName);

         

           $exploreLink = new htmlcodemaker('a');
           if ($UserLogic->isUserCommentator())
           {
                if ($arePlayerFinalizedBool)
                {
                   $exploreLink->set(array('href'=>"#","style"=>'text-decoration: none;color: #900;', 'class'=>'openCommentaryMatchLink','name'=>$gameID,'title'=>$MatchTitle,'text'=>'<b>Commentate on Match</b>'));
                }
                else
                {
                    $exploreLink->set(array('href'=>"#","style"=>'text-decoration: none;color: #900;','class'=>'openPlayerMatchMatchLink','name'=>$gameID,'title'=>$MatchTitle,'text'=>'<b>Commentate on Match</b>'));
                }
           }
           else
           {
               $exploreLink->set(array('href'=>"livematch/$gameID","style"=>'text-decoration: none;color: #900;', 'class'=>'openLiveMatchLink','name'=>$gameID,'title'=>$MatchTitle,'text'=>'<b>Spectate Live Match</b>'));
           }

            
            if ($isGameActiveBool)
            {

           $trimmedMatchTitle = preg_replace('/\s+/', '', $MatchTitle);

        $matchListContent .= "<div id='$trimmedMatchTitle'>";
        $matchListContent .= "<div align='center' style='padding-left:80px; text-align: center; width:400px; height:105px;'>";
        $matchListContent .= "<div class ='teamLogo ".$homeTeamShortName."_home_logo'></div><p style='float:left; padding:30px 0px 0px 0px;'><strong> $homeTeamName Vs.";
        $matchListContent .= " $awayTeamName </strong></p><div class ='teamLogo ".$awayTeamShortName."_home_logo'></div>";
        $matchListContent .= "</div>";
         $matchListContent .= "<h2>$MatchTitle</h2>";
         $matchListContent .= "<p><b>Venue: </b> $GameVenue</p>";
         $matchListContent .= "<p><B>Type:</B> $GameType</p>";
       $matchListContent .= "<p><B>Umpires:</B> $GameUmpire1, $GameUmpire2 and $TVUmpire </p>";
         $matchListContent .= "<p><B>Status:</B> $GameToss </p>";
         if($UserLogic->isLoggedOn())
         {
           $matchListContent .= "<p>".$exploreLink->output()."</p>";
         }
        
        $matchListContent .= "</div>";
            }




        }

$matchListContent .= '</div>';
         if($UserLogic->isLoggedOn())
         {
$matchListContent .= $this->listOldGames();
         }
             return $matchListContent;

        
    }


    private function listOldGames()
    {
      $GameAdmin = new GameAdmin();
        $GamesArray = $GameAdmin->getAllGames();
        $numberofPairEntries = count($GamesArray);
        $oldGameContent = "<h2>Previous Matches</h2>";
        for ($i=0;$i<($numberofPairEntries/2);$i++)
        {
            $x2 = 2*$i;
            //print_r($GamesArray[$x2]);
           $MatchTitle = $GamesArray[$x2]['GAME_TIT'];
           $GameType = $GamesArray[$x2]['GAME_TYPE'];
           $GameVenue = $GamesArray[$x2]['GAME_VEN'];
           $GameToss = $GamesArray[$x2]['GAME_TOSS'];
           $GameUmpire1 = $GamesArray[$x2]['GAME_UMP1'];
           $GameUmpire2 = $GamesArray[$x2]['GAME_UMP2'];
           $TVUmpire = $GamesArray[$x2]['GAME_UMP_TV'];
            $isGameActiveBool = $GamesArray[$x2]['GAME_ACTIVE'];
           $gameFinalResult = $GamesArray[$x2]['GAME_FINALRESLT'];
           $arePlayerFinalizedBool = $GamesArray[$x2]['GAME_PLAYERSFINALSD'];
           $gameID = $GamesArray[$x2]['GAME_GAME_ID'];
           $homeTeamName = $GamesArray[$x2]['TEAM_POOL_NAME'];
           $awayTeamName = $GamesArray[($x2+1)]['TEAM_POOL_NAME'];
            $homeTeamShortName = $GamesArray[$x2]['TEAM_POOL_SNAME'];
            $awayTeamShortName = $GamesArray[($x2+1)]['TEAM_POOL_SNAME'];
            $homeTeamShortName = strtolower($homeTeamShortName);
             $awayTeamShortName = strtolower($awayTeamShortName);

             $viewLink = new htmlcodemaker('a');
             $viewLink->set(array('href'=>"#","style"=>'text-decoration: none;color: #900;', 'class'=>'viewOldMatchLink','name'=>$gameID,'title'=>$MatchTitle,'text'=>'View Highlights'));
             if($isGameActiveBool != TRUE)
             {
 
                 $oldGameContent .= "<h4>$MatchTitle</h4>";
                $oldGameContent .= $homeTeamName ." Vs ". $awayTeamName."<br>";
                $oldGameContent .= $GameToss;
                if (strlen($gameFinalResult) > 4)
                {
                  $oldGameContent .= "<p>Game has been played. $gameFinalResult</p>";
                }
                else
                {
                    $oldGameContent .= "<br>";
                }
                $oldGameContent .= $viewLink->output();
                $oldGameContent .= "<hr/>";
             }




        }
        return $oldGameContent;
    }







    private function buildGameManagementTopButtons()
    {
         $UserLogic = new UserLogic();
         $topButtons = NULL;
       if ($UserLogic->isUserCommentator())
       {
        $topButtons = "<h2>Games</h2>";
        $topButtons .= $this->htmlelementsbuilder->buildButton("addGame", "Create New Game", "gameManagementButtons");
        $topButtons .= $this->htmlelementsbuilder->buildButton("updateGameDetails", "Update Active Game Details", "gameManagementButtons");
        $topButtons .= $this->htmlelementsbuilder->buildButton("deleteGames", "Remove Inactive Games", "gameManagementButtons");
       }
        return $topButtons;
    }

    public function showListAllGames()
    {
        return $this->buildListAllGames();
    }
    public function showInsertPlayerIntoForm($gameID)
    {
        return $this->buildInsertPlayerIntoForm($gameID);
    }

    public function showGameTossForm($homeTeamID,$homeTeamName,$awayTeamID,$awayTeamName)
    {
        return $this->buildGameTossForm($homeTeamID, $homeTeamName, $awayTeamID, $awayTeamName);
    }


    public function showGameTopPage()
    {
        return $this->buildGameManagementTopButtons();
    }

     public function showAddGameForm()
    {
        return $this->buildAddGameForm();
    }




}